package com.yaorange.module.common.service;

import cn.hutool.crypto.SecureUtil;
import com.yaorange.common.service.ISysBaseAPI;
import com.yaorange.module.system.repository.SysUserRepository;
import com.yaorange.pojo.SysUser;
import com.yaorange.utils.ThreadLocalUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @Description:
 * @Author: cq
 * @Date: 2025-06-26
 */
@Service
public class SysBaseImplAPI implements ISysBaseAPI {

    @Resource
    private SysUserRepository sysUserRepository;

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    @Override
    public SysUser getUserById(Long id) {
        return sysUserRepository.selectById(id);
    }

    /**
     * 添加任务
     * @param sysUser
     */
    @Override
    public void addUser(SysUser sysUser) {
        String userPassword = sysUser.getUserPassword();
        sysUser.setUserPassword(SecureUtil.md5(userPassword));
        sysUser.setCreateTime(LocalDateTime.now());
        String id = ThreadLocalUtil.get();
        String[] split = id.split("-");
        String userId = split[0];
        sysUser.setCreateBy(Long.valueOf(userId));
        sysUserRepository.insert(sysUser);
    }
}
